package mt.omid.dimomuth.mgm.xmlrpc;


import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.server.PropertyHandlerMapping;


public class VSPOTHandlerMapping extends PropertyHandlerMapping
{

    protected void registerPublicMethods( String pKey, Class pType ) throws XmlRpcException
    {
	Map map = new HashMap();
	Method [] methods = pType.getMethods();
	String name;
	Method [] mArray;
	for( int i = 0; i < methods.length; ++i )
	{
	    Method method = methods[ i ];
	    if( !( isHandlerMethod( method ) ) )
	    {
		continue;
	    }
	    name = method.getName();

	    Method [] oldMArray = ( Method [] ) ( Method [] ) map.get( name );
	    if( oldMArray == null )
	    {
		mArray = new Method [] { method };
	    }
	    else
	    {
		mArray = new Method [ oldMArray.length + 1 ];
		System.arraycopy( oldMArray, 0, mArray, 0, oldMArray.length );
		mArray[ oldMArray.length ] = method;
	    }
	    map.put( name, mArray );
	}

	for( Iterator iter = map.entrySet().iterator(); iter.hasNext(); )
	{
	    Map.Entry entry = ( Map.Entry ) iter.next();
	    name = ( String ) entry.getKey();
	    mArray = ( Method [] ) ( Method [] ) entry.getValue();
	    this.handlerMap.put( name, newXmlRpcHandler( pType, mArray ) );
	}
    }
}
